package com.hjimi.ski.model.base;

import com.hjimi.ski.callback.BaseCallback;
import com.hjimi.ski.utils.HttpUtil;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.HashMap;

import okhttp3.Call;
import okhttp3.Request;

/**
 * Created by Administrator on 2019/8/7 0007.
 */

public class PostHeadModel extends BaseModel<String> {

    @Override
    public void execute(final BaseCallback<String> callback) {

        int length = this.mParamsKey.length;
        int _length = this.mParamsValue.length;
        if (length==_length){
            HashMap<String, String> map = new HashMap<>();
            for (int i = 0; i < length; i++) {
                map.put(mParamsKey[i],mParamsValue[i]);
            }

            HttpUtil.requestPostHead(url,token, map, new StringCallback() {
                @Override
                public void onError(Call call, Exception e, int id) {
                    callback.onFailure(e.toString());
                }

                @Override
                public void onResponse(String response, int id) {
                    callback.onSuccess(response);
                }

                @Override
                public void onBefore(Request request, int id) {
                    callback.onBefore();
                }

                @Override
                public void onAfter(int id) {
                    callback.onComplete();
                }
            }, "1");
        }else {
            callback.onFailure("参数传递错误！");
        }

    }
}
